<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "util" %>
<%= javascript_include_tag "calendar" %>
<script>
function deleteAll(){
        if (!confirm('你确定要删除选定的条形码吗?'))
        {
            return false;
        }
        var sSel="",i=1;
        var oSel=document.getElementById("sel1");
        while(oSel){
                if (oSel.checked) sSel+=oSel.value+",";
                i++;
                oSel=document.getElementById("sel"+i);
        }
        delForm.codes.value = sSel;
        delForm.submit();
}
function checkNum(flag, msg_id, obj_name, msg_text){
        if (flag) {
                if ($(obj_name).value == "" || ! digCheck($(obj_name).value))
                {
                        $(msg_id).innerText = msg_text;
                        $(msg_id).style.display = "block";
                        return false;
                }
                else return true;
        }
        else {
                $(msg_id).style.display = "none";
        }
}
function checkDate()
{
        if ( checkNum(true,'id_prefix','code_prefix','前缀输入错误')
                && checkNum(true,'id_from','code_from','起始编号输入错误')
                && checkNum(true,'id_to','code_to','结束编号输入错误')
                && checkNum(true,'id_postfix','code_postfix','后缀输入错误')
           )
                frmCode.submit();
}
</script>
<h1>订单管理 - <span id="secondHeading">查询条形码</span></h1>
<form id="input-form" name="frmCode" action="/sale/query_code" method="post">
<TABLE border="0" id="INPUT_TABLE">
		<tr><td colspan="2">
			<% if @flash[:notice] -%>
					<div id="notice"><%= @flash[:notice] %></div>
				<% end -%>
			</td>
		</tr>
	<TR>
		<TD width="20%">前缀：</TD>
		<TD><input id="code_prefix" type="text" name="prefix" size="30" maxlength="20" onfocus ="checkNum(false,'id_prefix')" onblur="checkNum(true,'id_prefix',this.id,'前缀输入错误')"/> <div class="redNsg" id="id_prefix" style="display:none;"></TD>
	</TR>
        <TR>
		<TD>起始编号：</TD>
                <TD><input id="code_from" type="text" name="from" size="30" maxlength="20" onfocus ="checkNum(false,'id_from')" onblur="checkNum(true,'id_from',this.id,'起始编号输入错误')"/> <div class="redNsg" id="id_from" style="display:none;"></TD>
        </TR>
	<TR>
		<TD>结束编号：</TD>
		<TD><input id="code_to" type="text" name="to" size="30" maxlength="20" onfocus ="checkNum(false,'id_to')" onblur="checkNum(true,'id_to',this.id,'结束编号输入错误')"/> <div class="redNsg" id="id_to" style="display:none;"></TD>
	</TR>
        <TR>
		<TD>后缀：</TD>
		<TD><input id="code_postfix" type="text" name="postfix" size="30" maxlength="20" onfocus ="checkNum(false,'id_postfix')" onblur="checkNum(true,'id_postfix',this.id,'后缀输入错误')"/> <div class="redNsg" id="id_postfix" style="display:none;"></TD>
	</TR>
	<tr>
                <td colspan="2" align="right">
                        <TD><input type="button" class='sub' value="查询" onclick="checkDate()"></TD>
                </td>
        </tr>		
</TABLE>
</form>
<%if @codes%>
<form name="delForm" action="/sale/delete_code" method="post">
</p>
<TABLE border="0" id="LIST_TB">
	<TR id="LIST_TB_TITLE">
		<TD>条形码</TD>
		<TD>销售日期</TD>
                <!--<TD>客户</TD> -->
		<TD>产品</TD>
		<TD>选择</TD>
	</TR>
	<%i=1%>
	<%@codes.each do |code|%>
	<TR id="LIST_TB_CONTENT1">
		<TD><%=code.prefix+code.code+code.postfix%></TD>
		<TD><%=code.out_date_at%></TD>		
                <!--<TD><%=code.agent.name%></TD>-->
		<TD><%=code.product.name%></TD>
		<TD><input id="sel<%=i%>" type="checkbox" value="<%=code.id%>"/></TD>
		<%i=i+1%>
	</TR>
	<%end%>
	<input type="hidden" name="codes" value=""/>
</TABLE>
<div style="margin-top: 20px;margin-left: 90%"><input type="button" id="btnDelAll" class="sub" value="删除" onclick="deleteAll();" /></div>
</form>
<table>
        <tr>
                <td>
                        <input type="button" value="打印当前页" class="sub" onclick="openPrintWindow('LIST_TB')"/>
                        <input type="button" value="导出当前数据" class="sub" onclick="CellAreaExcel('LIST_TB')"/>
                </td>
        </tr>
</table>
<%end%>
